<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>问卷调查</title>
    <meta name="description" content="问卷调查" />
    <meta name="format-detection" content="telephone=no"/>
    <meta name="wap-font-scale" content="no">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="./css/modal-px.css?" media="screen" title="no_title" charset="utf-8">
    <link rel="stylesheet" href="../common/css/plugins.css" media="screen" title="no_title" charset="utf-8">
    <style media="screen" title="no_title">input{-webkit-appearance: none;}.clear:after{content:'';display:block;clear:both;width:0;height:0}*{margin:0;padding:0;-webkit-tap-highlight-color:rgba(255,255,255,0);font-family:Helvetica,sans-serif;-webkit-touch-callout:none;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box}a:active,a:hover,a:link,a:visited{text-decoration:none;outline:0}ul,li{list-style:none}html,body{width:100%;font-size:20px;background-color:#f0f0f0}*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box;outline:0}.alert-msg{position:fixed;z-index:10000;top:40%;margin-left:-6.75rem;text-align:center;opacity:0;left:50%;color:#fff;background-color:rgba(0,0,0,.65);padding:.7rem 1.6rem;-webkit-transition:.4s ease-out;transition:.4s ease-out;font-size:.7rem;border-radius:.15rem;-webkit-transform:translate3d(0,0,0) scale(1.185);transform:translate3d(0,0,0) scale(1.185);-webkit-transition-property:-webkit-transform,opacity;transition-property:transform,opacity;box-sizing:border-box}.alert-msg.in{opacity:1;-webkit-transform:translate3d(0,0,0) scale(1);transform:translate3d(0,0,0) scale(1)}.alert-msg.out{-webkit-transform:translate3d(0,0,0) scale(0.815);transform:translate3d(0,0,0) scale(0.815)}.confirm-bg{position:absolute;left:0;top:0;bottom:0;right:0;z-index:9998;background-color:rgba(69,69,69,.6);visibility:hidden;opacity:0;-webkit-transition-duration:400ms;transition-duration:400ms}.confirm-bg.confirm-bg-visible{visibility:visible;opacity:1}.confirm-msg{opacity:0;-webkit-transform:translate3d(0,-50%,0) scale(1.185);transform:translate3d(0,-50%,0) scale(1.185);-webkit-transition-property:-webkit-transform,opacity;transition-property:transform,opacity;left:50%;top:50%;margin-left:-6.25rem;z-index:9999;position:absolute;width:12.5rem}.confirm-msg.in{opacity:1;-webkit-transition-duration:400ms;transition-duration:400ms;-webkit-transfrom:translate3d(0,0,0) scale(1);transform:translate3d(0,0,0) scale(1)}.confirm-msg.out{opacity:0;z-index:10999;-webkit-transition-duration:400ms;transition-duration:400ms;-webkit-transform:translate3d(0,0,0) scale(0.815);transform:translate3d(0,0,0) scale(0.815)}.confirm-msg .confirm-msg-title{border-top-left-radius:.25rem;border-top-right-radius:.25rem;background-color:#fff;height:1.725rem;border-bottom:1px solid #EBEBF5;line-height:1.725rem;text-align:center;font-size:.85rem;color:#00a5e0}.confirm-msg .confirm-msg-content{background-color:#fff;padding:.5rem .65rem;border-bottom-left-radius:.25rem;border-bottom-right-radius:.25rem}.confirm-msg .confirm-msg-content.has-btn{border:0;border-radius:0}.confirm-msg .confirm-msg-content p{color:#4F545B;font-size:.7rem}.confirm-msg .confirm-msg-btns{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;-webkit-box-orient:horizontal;-ms-box-orient:horizontal;-moz-box-orient:horizontal;-webkit-flex-flow:row nowrap;-ms-flex-flow:row nowrap;-moz-flex-flow:row nowrap;flex-flow:row nowrap;border-top:1px solid #E4E4E4;padding:.175rem 0;background:#fff;border-bottom-left-radius:.25rem;border-bottom-right-radius:.25rem}.confirm-msg .confirm-msg-btns span{display:block;-webkit-box-flex:1;-moz-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1;height:1.85rem;line-height:1.85rem;font-size:.7rem;text-align:center;box-sizing:border-box;color:#4F545B}.confirm-msg .confirm-msg-btns span:first-child{color:#00a5e0}.confirm-msg .confirm-msg-btns span+span{border-left:1px solid #E4E4E4}.confirm-msg .confirm-msg-close{margin:1.5rem auto 0;width:1.45rem;height:1.45rem;background:url(/images/close.png) no-repeat;background-size:1.45rem}body,html{width:100%;height:100%;}html{background:#f7f7f7}body{padding:14px 11px 0;background:#fff;overflow:scroll;-webkit-overflow-scrolling:touch}input{border:1px solid #ddd;-webkit-appearance:none;padding:0 8px;font-size:14px}.hidden{width:0;height:0;opacity:0;overflow:hidden}header{text-align:center;font-size:16px;line-height:22px;background:#fa8b39;color:#fff;padding:16px 20px}section article{padding:.55rem 0;font-size:14px;line-height:20px;color:#666;border-bottom:1px solid #ddd}section ul li{display:none}section ul li.show{display:block}section ul li .title{font-size:15px;color:#333;line-height:24px;vertical-align:top;font-weight:500;margin:13px 0}section ul li .title i{display:inline-block;color:red;font-size:15px;line-height:17px;vertical-align:baseline;font-weight:600}section ul li .title:before{content:'';width:4px;height:24px;display:inline-block;background:#fa8b39;vertical-align:top;margin-right:10px}section ul li .options{padding:0 8px;background:#fff;border:1px solid #ddd;-webkit-border-radius:4px;-moz-border-radius:4px;-ms-border-radius:4px;-o-border-radius:4px;border-radius:4px}section ul li .options .option{font-size:0;border-bottom:1px solid #ddd;-webkit-box-orient:horizontal;-ms-box-orient:horizontal;-moz-box-orient:horizontal;-webkit-flex-flow:row nowrap;-ms-flex-flow:row nowrap;-moz-flex-flow:row nowrap;flex-flow:row nowrap;display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;-webkit-box-pack:start;-ms-flex-pack:start;-webkit-justify-content:flex-start;justify-content:flex-start;-webkit-box-align:center;-ms-flex-align:center;-webkit-align-items:center;align-items:center}section ul li .options .option:last-child{border-bottom:0}section ul li .options .option i{min-width:16px;width:16px;height:16px;display:block;vertical-align:top;margin:10px 10px 10px 0}section ul li .options .option i.radio{background:url(./img/radio_icon.png) no-repeat center;background-size:contain}section ul li .options .option i.checkbox{background:url(./img/checkbox_icon.png) no-repeat center;background-size:contain}section ul li .options .option span{display:block;font-size:14px;color:#595959;line-height:16px;margin:10px 0}section ul li .options .option.selected i.radio{background:url(./img/selected_radio_icon.png) no-repeat center;background-size:contain}section ul li .options .option.selected i.checkbox{background:url(./img/selected_checkbox_icon.png) no-repeat center;background-size:contain}section ul li .options .option.selected span{color:#bebebe}section ul li .options .option img{display:block;min-width:28px;width:28px;height:28px;margin:4px 0 4px 6px}section ul li .options .option input{display:block;margin:4px 0 4px 6px;height:30px;min-width:50px;border-radius:3px;-webkit-border-radius:3px;-webkit-box-flex:1;-moz-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1}section ul li .remark{font-size:14px;color:#595959;padding:15px 0 0;-webkit-box-orient:horizontal;-ms-box-orient:horizontal;-moz-box-orient:horizontal;-webkit-flex-flow:row nowrap;-ms-flex-flow:row nowrap;-moz-flex-flow:row nowrap;flex-flow:row nowrap;display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex}section ul li .remark label{font-size:14px;color:#595959;line-height:34px}section ul li .remark input{height:34px;border:1px solid #ddd;-webkit-border-radius:4px;-moz-border-radius:4px;-ms-border-radius:4px;-o-border-radius:4px;border-radius:4px;-webkit-box-flex:1;-moz-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1}section ul li .blank input{width:100%;height:34px;border:1px solid #ddd;-webkit-border-radius:4px;-moz-border-radius:4px;-ms-border-radius:4px;-o-border-radius:4px;border-radius:4px}footer{padding:15px 0}footer a{display:block;height:40px;line-height:40px;background:#fa8b39;color:#fff;text-align:center;font-size:16px;-webkit-border-radius:4px;-moz-border-radius:4px;-ms-border-radius:4px;-o-border-radius:4px;border-radius:4px}footer a.disabled{background-color:#fcc59c}#main{display:none;}section article img{width:100%;vertical-align:middle;}</style>
</head>
<body style="visibility: hidden;">
<div class="main" id="main">
    <header id="act-title"></header>
    <section>
        <article id="act-desc"></article>
        <ul id="act-list"></ul>
    </section>
    <footer>
        <a class="submit" id="submit">提交</a>
    </footer>
    <div class="hidden">
        <img src="./img/selected_checkbox_icon.png" alt=""/>
        <img src="./img/selected_radio_icon.png" alt=""/>
    </div>
</div>
<script type="text/template" id="question-template">
    {{each quizzes as item i}}
    <li class="{{item.configurations.linked?'':'show'}}"  data-type="{{item.type}}" data-id="{{item.id}}" data-required="{{item.validations.required?1:0}}" data-islinked="{{item.configurations.linked?1:0}}">
        {{if item.validations.required==1}}
        <div class="title">{{i+1}}. {{item.title}}<i>*</i></div>
        {{else}}
        <div class="title">{{i+1}}. {{item.title}}</div>
        {{/if}}
        {{if item.type=='1'}}
        <div class="options">
            {{each item.options as option j}}
            <div class="option" data-type="radio" data-id="{{option.id}}">
                <i class="radio"></i>
                <span>{{j+1 | numberFormat}} {{option.text}}</span>
                {{if option.resource}}
                <img src="{{option.resource}}" alt=""/>
                {{/if}}
                {{if option.fillable}}
                <input type="text"/>
                {{/if}}
            </div>
            {{/each}}
        </div>
        {{/if}}
        {{if item.type=='2'}}
        <div class="options">
            {{each item.options as option j}}
            <div class="option" data-type="checkbox" data-id="{{option.id}}">
                <i class="checkbox"></i>
                <span>{{j+1 | numberFormat}} {{option.text}}</span>
                {{if option.resource}}
                <img src="{{option.resource}}" alt=""/>
                {{/if}}
                {{if option.fillable}}
                <input type="text"/>
                {{/if}}
            </div>
            {{/each}}
        </div>
        {{/if}}
        {{if item.type=='3'}}
        <div class="blank">
            <input type="text"/>
        </div>
        {{/if}}
    </li>
    {{/each}}
</script>
<script type="text/template" id="question-template1">
    {{each quizzes as item i}}
    <li class="{{reason&&reason=='already-involved'?'show':''}}"  data-type="{{item.type}}" data-id="{{item.id}}" data-required="{{item.validations.required?1:0}}" data-islinked="{{item.configurations.linked?1:0}}">
        {{if item.validations.required==1}}
        <div class="title">{{i+1}}. {{item.title}}<i>*</i></div>
        {{else}}
        <div class="title">{{i+1}}. {{item.title}}</div>
        {{/if}}
        {{if item.type=='1'}}
        <div class="options">
            {{each item.options as option j}}
            <div class="option {{option.selected||option.selected=='true'?'selected':''}}" data-type="radio" data-id="{{option.id}}">
                <i class="radio"></i>
                <span>{{j+1 | numberFormat}} {{option.text}}</span>
                {{if option.resource}}
                <img src="{{option.resource}}" alt=""/>
                {{/if}}
                {{if option.fillable}}
                <input type="text" readonly="readonly" value="{{option.fill_content}}"/>
                {{/if}}
            </div>
            {{/each}}
        </div>
        {{/if}}
        {{if item.type=='2'}}
        <div class="options">
            {{each item.options as option j}}
            <div class="option {{option.selected||option.selected=='true'?'selected':''}}" data-type="checkbox" data-id="{{option.id}}">
                <i class="checkbox"></i>
                <span>{{j+1 | numberFormat}} {{option.text}}</span>
                {{if option.resource}}
                <img src="{{option.resource}}" alt=""/>
                {{/if}}
                {{if option.fillable}}
                <input type="text" readonly="readonly" value="{{option.fill_content}}"/>
                {{/if}}
            </div>
            {{/each}}
        </div>
        {{/if}}
        {{if item.type=='3'}}
        <div class="blank">
            <input readonly="readonly" type="text" value="{{item.options}}"/>
        </div>
        {{/if}}
    </li>
    {{/each}}
</script>
<script type="text/javascript">
    (function (doc, win) {
        var docEl = doc.documentElement,
            resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
            recalc = function () {
                var clientWidth = docEl.clientWidth;
                if (!clientWidth) return;
                // 针对uc横竖屏rem html没有重绘的问题
                var style;
                if (style = document.getElementById("forhtml")) {
                    style.parentNode.removeChild(style);
                }
                style = document.createElement("style");
                style.id = "forhtml";
                document.head.appendChild(style);
                style.appendChild(document.createTextNode("html{font-size:" + 20 * (clientWidth / 320) + "px !important;}"));
            };
        recalc();
        document.body.style.visibility = 'visible';
        if (!doc.addEventListener) return;
        win.addEventListener(resizeEvt, recalc, false);
        doc.addEventListener('DOMContentLoaded', recalc, false);
        var a = document.getElementsByTagName('a');
        for (var i = 0; i < a.length; i++) {
            a[i].addEventListener('touchstart', function () {
            }, false);
        }
    })(document, window);
    //获取链接中参数列表
    function GetRequest(url) {
        if (!url || url.indexOf('?') == -1) {
            return {};
        }
        var url = url.split('?')[1].split('#')[0]; //获取url中"?"符后"#"前的字串
        var theRequest = new Object();
        var str = decodeURI(url);
        var strs;
        if (str.indexOf("&") != -1) {
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        } else {
            theRequest[str.split("=")[0]] = decodeURIComponent(str.split("=")[1]);
        }
        return theRequest;
    }
</script>
<script type="text/javascript" charset="utf-8" src="../common/lib/zepto.min.js"></script>
<script type="text/javascript" charset="utf-8" src="../common/lib/zepto-adapter.js"></script>
<script type="text/javascript" charset="utf-8" src="../common/lib/template.min.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/modal.js"></script>
<script type="text/javascript" charset="utf-8" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript" charset="utf-8" src="../common/js/weixinshare.js"></script>
<script>
    function QRCode(qrcode){
        var $mask = $('<div class="mask-layer">' +
            '             <div class="cover"></div>' +
            '             <div class="content">'+
            //            '                 <div class="close icon"></div>' +
            '                 <div class="qr-code"></div>' +
            '                 <div class="slogan">扫描二维码,关注公众号后参与活动</div>' +
            '             </div>' +
            '         </div>');
        $mask.find('.close.icon').click(function(e){
            $mask.remove();
        });
        return {
            open: function(){
                if(qrcode){
                    $mask.find('.qr-code').html('<img src="'+qrcode+'" alt="二维码"/>');
                }
                $('body').append($mask);
            },
            close: function(){
                $mask.remove();
            }
        }
    }
    function forbidShare() {
        function onBridgeReady() {
            WeixinJSBridge.call('hideOptionMenu');
        }

        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        } else {
            onBridgeReady();
        }
    }
</script>
<script type="text/javascript">
    $(document).ready(function () {
        window.parameter = GetRequest(window.location.href);
        var isWechat = false,isAPP = false,isFollow = false,isCode=false,isPart=false,activities={};
        //时间格式化
        Date.prototype.Format = function (time) {
            var obj = {
                "M+": this.getMonth() + 1,
                "d+": this.getDate(),
                "h+": this.getHours(),
                "m+": this.getMinutes(),
                "s+": this.getSeconds(),
                "q+": Math.floor((this.getMonth() + 3) / 3),
                "S": this.getMilliseconds()
            };
            if(/(y+)/.test(time)){
                time = time.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length));
            }
            for (var key in obj){
                if (new RegExp("(" + key + ")").test(time)){
                    time = time.replace(RegExp.$1, (RegExp.$1.length == 1) ? (obj[key]) : (("00" + obj[key]).substr(("" + obj[key]).length)));
                }
            }
            return time;
        }
        var start_time = new Date().Format("yyyy-MM-dd hh:mm:ss");

        //生成字母表
        function generateAlphabet(){
            var alphabet = [];
            for(var i=65;i<95;i++){
                alphabet.push(String.fromCharCode(i));
            }
            return alphabet;
        }
        var alphabet = generateAlphabet();

        //验签
        var isSignPass = -2,vote_token='';
        function signCallBack() {
            if(window.parameter.mfSign){
                if(window.parameter.userid || window.parameter.uid){
                    $.ajax({
                        url:'/api/app/sign/mf.php',
                        data:window.parameter,
                        type: 'get',
                        success: function(ajaxData) {
                            if (ajaxData.code == 200) {
                                isSignPass = 1;
                                vote_token = ajaxData.vote_token;
                            } else {
                                alert('验签失败：'+ajaxData.message);
                                isSignPass = 0;
                            }
                        },
                        error: function(){
                            alert('网络异常！');
                            isSignPass = 0;
                        }
                    });
                }else{
                    isSignPass = -1;
                }
            }else{
                isSignPass = -2;
            }
        }
        function signCallBack(callback) {
            if(window.parameter.mfSign){
                if(window.parameter.userid || window.parameter.uid){
                    $.ajax({
                        url: '/api/app/sign/mf.php',
                        data:window.parameter,
                        type: 'get',
                        success: function(ajaxData) {
                            if (ajaxData.code == 200) {
                                isSignPass = 1;
                                vote_token = ajaxData.vote_token;
                            } else {
                                alert('验签失败!');
                                isSignPass = 0;
                            }
                            callback();
                        },
                        error: function(){
                            alert('网络异常！');
                            isSignPass = 0;
                        }
                    });
                }else{
                    isSignPass = -1;
                }
            }else{
                isSignPass = -2;
            }
        }
        function judgeSignPass(callback){
            if(window.parameter['ways']!='wechat'){
                signCallBack(callback);
            }else{
                isSignPass = 1;
                vote_token = window.parameter['vote_token'];
                callback();
            }
        }
        judgeSignPass(function(){});

        //提交验证
        var validateObj = {useable:false,comment:'验证失败',reason:'',quizzes:[]};
        var act_info = '';
        function submitValidate(callback) {
            $.ajax({
                type: 'GET',
                url: '/api/activities/' + window.parameter['act_id'] + '/quizzes/useable?uid=' + window.parameter['uid'],
                success: function (data) {
                    validateObj = data.data;
                    if (data.code == 200) {
                        callback(data.data);
                    } else {
                        alert('验证失败：' + data.message);
                    }
                }
            });
        }
        submitValidate(function(data){
            //请求信息
            requestActInfo(function(data){
                act_info = data;
                $('#act-title').html(data.name);
                $('#act-desc').html(data.description);
                if(data.background_img){
                    $('body').css({
                        'background': 'url('+data.background_img+') no-repeat center top',
                        'background-size': '100% auto',
                    });
                }
                //===============================
                activities = data;
                isWechat = (window.parameter.ways == 'wechat');//是否开启微信
                isAPP = (activities.publishing.app.is_open =='on');//是否开启APP
                isFollow = (window.parameter['following']!=1);//是否关注
                isCode = Boolean(activities.publishing.wechat.qr_code[0]);//是否上传二维码
                if(isWechat){
                    if(isFollow){
                        isPart = true;
                    }else{
                        if(isCode){
                            var qrCode = QRCode(activities.publishing.wechat.qr_code[0]).open();
                        }else{
                            isPart = true;
                        }
                    }
                }else{
                    //APP
                }
                if (typeof wxshare != 'undefined' && (activities.shares.isopen == 'on' || activities.shares.isopen == '1')) {
                    var shareLink = '';
                    if(isWechat){
                        shareLink =window.location.origin+'/wechat/shares?id='+window.parameter.act_id;
                    }else{
                        shareLink = window.location.origin + location.pathname + '?act_id=' + wxshare.getUrlParam('act_id');
                    }
                    wxshare.share({
                        title: activities.shares.title,
                        desc: activities.shares.content,
                        link: shareLink,
                        imgUrl: activities.shares.thumb,
                    });
                }else{
                    forbidShare();
                }
                //===========================
            });
            if(!data.useable){
                if(data.reason=='already-involved'){
                    $('#main').show();
                    $('#submit').addClass('disabled').text('已参与');
                }else{
                    $.alert(data.comment);
                }
            }else{
                $('#main').show();
            }
        });

        //过滤器
        template.helper('numberFormat', function (number) {
            return  String.fromCharCode(64+parseInt(number));
        });

        //渲染问题列表(未参与)
        function renderQuestion(data){
            var links = {},idIndex=[];
            $.each(data.quizzes,function(i,item){
                idIndex.push(item.id);
                if(item.configurations.linked){
                    if(!links[item.configurations.link_id]){
                        links[item.configurations.link_id] = [];
                    }
                    links[item.configurations.link_id].push({
                        to_id: item.id,
                        option_ids: item.configurations.link_option_ids,
                    });
                }
            });
            $('#act-list').html(template('question-template',data));
            setTimeout(function(){
                var $quizList = $('#act-list li'),$optionList=$('#act-list .options .option');
                function isShow(quiz_id){
                    if(links[quiz_id]){
                        $.each(links[quiz_id],function(k,item){
                            var $quiz = $quizList.eq(idIndex.indexOf(item.to_id));
                            $quiz.removeClass('show');
                            $quiz.find('.option').removeClass('selected');
                            isShow(item.to_id);
                        });
                    }
                }
                $optionList.off('click').on('click',function(e){
                    e.preventDefault();
                    e.stopPropagation();
                    var $this = $(this);
                    var quiz_id = $this.parents('li').data('id');
                    var option_id = $this.data('id');
                    var type = $this.data('type');
                    if(type=='radio'){
                        $this.siblings('.option').removeClass('selected');
                        $this.addClass('selected');
                        if(links[quiz_id]){
                            $.each(links[quiz_id],function(i,item){
                                if(item.option_ids.indexOf(option_id)>-1){
                                    $quizList.eq(idIndex.indexOf(item.to_id)).addClass('show');
                                }else{
                                    $quizList.eq(idIndex.indexOf(item.to_id)).removeClass('show');
                                    var $quiz = $quizList.eq(idIndex.indexOf(item.to_id));
                                    $quiz.removeClass('show');
                                    $quiz.find('.option').removeClass('selected');
                                    isShow(item.to_id);
                                }
                            });
                        }
                    }else if(type=='checkbox'){
                        $this.toggleClass('selected');
                        if(links[quiz_id]){
                            $.each(links[quiz_id],function(i,item){
                                var flag = false;
                                $this.parents('.options').find('.option.selected').each(function(i,option){
                                    if(item.option_ids.indexOf($(option).data('id'))>-1){
                                        flag = true;
                                    }
                                });
                                if(flag){
                                    $quizList.eq(idIndex.indexOf(item.to_id)).addClass('show');
                                }else{
                                    var $quiz = $quizList.eq(idIndex.indexOf(item.to_id));
                                    $quiz.removeClass('show');
                                    $quiz.find('.option').removeClass('selected');
                                    isShow(item.to_id);
                                }
                            });
                        }
                    }
                });
                $('#act-list .options .option input').off('click').on('click',function(e){
                    e.preventDefault();
                    e.stopPropagation();
                });
                $('#act-list .options .option img').off('click').on('click',function(e){
                    e.preventDefault();
                    e.stopPropagation();
                });
            },10);
        }
        //渲染问题列表(已参与)
        function renderQuestionAready(data){
            var links = {},idIndex=[];
            $('#act-list').html(template('question-template1',data));
            setTimeout(function(){
                var $quizList = $('#act-list li'),$optionList=$('#act-list .options .option');
                $('#act-list .options .option input').off('click').on('click',function(e){
                    e.preventDefault();
                    e.stopPropagation();
                });
                $('#act-list .options .option img').off('click').on('click',function(e){
                    e.preventDefault();
                    e.stopPropagation();
                });
                if (self != top) {
                    window.android_iframe.setIFrameHeight(calcPageHeight(document),window.parameter['act_id']);
                }
            },10);
        }

        //请求活动信息
        function requestActInfo(callback){
            $.ajax({
                type: 'GET',
                url: '/api/activities/'+window.parameter['act_id']+'/quizzes',
                success: function (data) {
                    if (data.code == 200) {
                        callback(data.data.activity);
                        if(validateObj.reason=='already-involved'){
                            renderQuestionAready(validateObj);
                        }else{
                            renderQuestion(data.data);
                        }
                        return data.data;
                    }
                }
            });
        }

        //提交表单
        $('#submit').on('click',function(e){
            e.preventDefault();
            e.stopPropagation();
            if($(this).hasClass('disabled')){
                return;
            }
            if(!isPart){
                if(isSignPass == -2){
                    if (activities.publishing.app.app_urls[0]) {
                        $.confirm('请下载APP参与活动?',
                            function () {
                                location.href = activities.publishing.app.app_urls[0];
                            },
                            function () {
                            }
                        );
                    } else {
                        $.alert('请下载APP参与活动');
                    }
                    return;
                }
                if(isSignPass == -1) {
                    window.location.href = window.location.href + '&noLogin=true';
                    return;
                }
                if(isSignPass == 0){
                    $.alert('非法请求，请在App中打开');
                    return;
                }
            }
            if(!validateObj.useable){
                $.alert(validateObj.comment);
                return;
            }
            var $this = $(this),sheets = [],$li = $('#act-list li.show'),flag=true;
            $li.each(function(i,item){
                var options = [],contents=[],$item=$(item);
                if($item.data('type')<3){
                    $(item).find('.option.selected').each(function(j,option){
                        options.push($(this).data('id'));
                        contents.push($(this).find('input[type=text]').val());
                    });
                    if(options.length==0&&$item.data('required')==1){
                        $.alert('第'+($item.index()+1)+'题请至少选择一项');
                        flag = false;
                        return false;
                    }
                }else if($item.data('type')==3){
                    contents[0] = $(item).find('.blank input[type=text]').val();
                    if(contents[0]==''&&$item.data('required')==1){
                        $.alert('第'+($item.index()+1)+'题必填');
                        flag = false;
                        return false;
                    }
                }
                sheets.push({
                    quiz_id: $(item).data('id'),
                    option_id: options,
                    fill_content: contents
                });
            });
            if(!$this.hasClass('disabled')&&flag){
                $this.addClass('disabled');
                var postData =  {
                    activity_id: window.parameter['act_id'],
                    sheets: sheets,
                    uid: window.parameter['uid'],
                    start_time: start_time,
                    vote_token: vote_token
                };
                $.ajax({
                    type: 'POST',
                    url: '/api/sheets/multiple',
                    data: JSON.stringify(postData),
                    dataType: 'application/json; charset=utf-8',
                    contentType: "application/json; charset=utf-8",
                    success: function(data){
                        data = JSON.parse(data);
                        if(data.code==200){
                            $.alert('提交成功');
                            $this.text('已参与');
                            judgeSignPass(function(){});
                        }else{
                            $this.removeClass('disabled');
                            $.alert(data.message);
                        }
                    },
                    error: function(data){
                        $this.removeClass('disabled');
                        alert(data.message);
                    }
                });
            }
        });
    });
</script>
</body>
</html>